<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>{{if com_id}} >>> {{com_id}} {{/if}}{{title}}</title>
</head>

<body>
    <form id="form" enctype="multipart/form-data">
        <textarea name="content" id="content" cols="30" rows="10" placeholder="" required data-id="{{theme_id}}" data-comid="{{com_id}}"></textarea>
        <input type="file" id="photo" name="photo" data-id="{{theme_id}}" required autocomplete="off" accept=".jpg,.png,.gif">
        <input type="button" id="submit" value="发表">
    </form>
</body>

</html>
<script src="/js/jquery.min.js"></script>
<script>
    //    function getQueryVariable(variable)
    //    {
    //        var query = window.location.search.substring(1);
    //        var vars = query.split("&");
    //        for (var i=0;i<vars.length;i++) {
    //            var pair = vars[i].split("=");
    //            if(pair[0] == variable){return pair[1];}
    //        }
    //        return(false);
    //    }
    var theme_id = $('#photo').data('id');
    if (theme_id) {
        $('#submit').click(function (event) {
            var id = $('textarea').data('id');
            var comer_id = '';
            if ($('textarea').data('comid') != null) {
                comer_id = $('textarea').data('comid');
            }
            var data = new FormData($('#form')[0]);
            console.log(data);
            console.log(comer_id);
            $.ajax({
                url: '/comment/reply?theme_id=' + id + '&comer_id=' + comer_id,
                type: 'post',
                data: data,
                cache: false,
                processData: false,
                contentType: false,
                success: function (resData) {
                    console.log(resData);
                    alert(resData.message);
                    if (resData.code == 0) {
                        location.href = '/login';
                    }
                    location.href = '/theme.html?id=' + id;
                }
            });
        });
    } else {

        $('#submit').click(function (event) {
            // event.preventDefault();
            var data = new FormData($('#form')[0]);
            console.log(data);
            $.ajax({
                type: "post",
                url: "/comment/posting",
                data: data,
                cache: false,
                processData: false,
                contentType: false,
                success: function (resData,status,jqXHR) {
                    alert(resData.message);
                    if (resData.code == 0) {
                        location.href = '/register2';
                    }
                    location.href = '/index3.html';
                }
            });

            // $.ajax('/comment/posting', data, function (resData) {
            //     console.log(resData);
            //     alert(resData.message);
            //     if (resData.code == 0) {
            //         location.href = '/register2';
            //     }
            //     location.href = '/index3.html';
            // })
        });
    }
</script>